package cn.lg.soar.core.util.easyexcel.translate;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;

/**
 * 翻译处理器
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
public class TranslateConverterWriteHandler implements CellWriteHandler {

    @Override
    public void beforeCellCreate(CellWriteHandlerContext context) {
        Converter<?> converter = context.getExcelContentProperty().getConverter();
        if (converter != null) {
            return;
        }
        ExcelContentProperty excelContentProperty = context.getExcelContentProperty();
        InnerTranslateConverter<?> innerTranslateConverter = Utils.getConverter(excelContentProperty.getField());
        if (innerTranslateConverter != null) {
            context.getExcelContentProperty().setConverter(innerTranslateConverter);
        }
    }

}
